package com.efast.dmom.aps.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.bean.Shift;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.ShiftService;

@Controller
@RequestMapping(value = "/shift")
public class ShiftController {
	@Autowired
	private ShiftService shiftService;

	@RequestMapping(value = "/operateByShift")
	public @ResponseBody ResultBean operateByShift(@RequestBody Shift shift) {
		// Determine the new
		if (shift.getInnnerData().getModificationFlag() == IModificationFlags.NEW) {
			return shiftService.save(shift);
			// Judge update
		} else if (shift.getInnnerData().getModificationFlag() == IModificationFlags.MODIFIED) {
			return shiftService.update(shift);
			// Judge to delete
		} else if (shift.getInnnerData().getModificationFlag() == IModificationFlags.DELETED) {
			return shiftService.delete(shift);
		}
		return null;
	}

	/* 查询班次信息 */
	@RequestMapping("/getAll")
	public @ResponseBody ResultBean getAllShift() {
		ResultBean result = new ResultBean(true, "");
		List<Shift> list = shiftService.getAll();
		result.setObject(list);
		return result;
	}

	/* 通过shiftId获取班次信息 */
	@RequestMapping("/getShiftByShiftId")
	public @ResponseBody ResultBean getShiftByShiftId(@RequestBody long shiftId) {
		ResultBean result = new ResultBean(true, "");
		Shift shiftInfo = shiftService.getShiftByShiftId(shiftId);
		result.setObject(shiftInfo);
		return result;
	}
	/* 通过shiftName获取班次信息 */
	@RequestMapping("/getShiftByShiftCode")
	public @ResponseBody ResultBean getShiftByShiftCode(@RequestBody String shiftCode) {
		ResultBean result = new ResultBean(true, "");
		Shift shiftInfo = shiftService.getShiftByShiftCode(shiftCode);
		result.setObject(shiftInfo);
		return result;
	}
	
	/* 通过shiftName获取班次信息 */
	@RequestMapping("/getShiftByShiftName")
	public @ResponseBody ResultBean getShiftByShiftName(@RequestBody String shiftName) {
		ResultBean result = new ResultBean(true, "");
		Shift shiftInfo = shiftService.getShiftByShiftName(shiftName);
		result.setObject(shiftInfo);
		return result;
	}
}
